//package com.zjj.lbw.ai.old.controller;
//
//import com.zjj.lbw.ai.old.rag.DocumentService;
//import org.springframework.ai.chat.ChatClient;
//import org.springframework.ai.chat.Generation;
//import org.springframework.ai.chat.prompt.Prompt;
//import org.springframework.ai.chat.prompt.PromptTemplate;
//import org.springframework.ai.document.Document;
//import org.springframework.ai.embedding.EmbeddingClient;
//import org.springframework.ai.image.ImageClient;
//import org.springframework.ai.image.ImagePrompt;
//import org.springframework.ai.image.ImageResponse;
//import org.springframework.ai.openai.OpenAiAudioTranscriptionClient;
//import org.springframework.ai.openai.OpenAiChatOptions;
//import org.springframework.ai.openai.audio.transcription.AudioTranscriptionPrompt;
//import org.springframework.ai.openai.audio.transcription.AudioTranscriptionResponse;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.core.io.Resource;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.List;
//import java.util.Map;
//
//@RestController
//public class ChatController {
//    @Autowired
//    private ChatClient chatClient;
//
//    @Autowired
//    private ImageClient imageClient;
//
//    @Value("classpath:/jfk.flac")
//    private Resource audioFile;
//
//    @Autowired
//    private EmbeddingClient embeddingClient;
//
//    @Autowired
//    private OpenAiAudioTranscriptionClient audioTranscriptionClient;
//
//    @Autowired
//    private DocumentService documentService;
//
//    @GetMapping("/chat")
//    public String generate(@RequestParam String message) {
//        return chatClient.call(message);
//    }
//
//    @GetMapping("/chatFun")
//    public String generateWithFun(@RequestParam String message) {
//        Prompt prompt = new Prompt(message, OpenAiChatOptions.builder().withFunction("dateService").build());
////        Prompt prompt = new Prompt(message, OpenAiChatOptions.builder().withFunctionCallbacks(
////                List.of(FunctionCallbackWrapper.builder(new DateService())
////                        .withName("dateService")
////                        .withDescription("获取指定地点的当前时间").build())
////        ).build());
//        Generation generation = chatClient.call(prompt).getResult();
//        return (generation != null) ? generation.getOutput().getContent() : "";
//    }
//
//    @GetMapping("/image")
//    public String image(@RequestParam String message) {
//        ImagePrompt imagePrompt = new ImagePrompt(message);
//        ImageResponse imageResponse = imageClient.call(imagePrompt);
//        return imageResponse.getResult().getOutput().getUrl();
//    }
//
//    @GetMapping("/audio")
//    public String audio() {
//        AudioTranscriptionPrompt transcriptionRequest = new AudioTranscriptionPrompt(audioFile);
//        AudioTranscriptionResponse response = audioTranscriptionClient.call(transcriptionRequest);
//        return response.getResult().getOutput();
//    }
//
//    @GetMapping("/embedding")
//    public List<Double> embedding(@RequestParam String message) {
//        return embeddingClient.embed(message);
//    }
//
//    @GetMapping("/document")
//    public List<Document> document() {
//        return documentService.loadText();
//    }
//
//    @GetMapping("/documentSearch")
//    public List<Document> documentSearch(@RequestParam String message) {
//        return documentService.search(message);
//    }
//
//    @GetMapping("/documentMetadataSearch")
//    public List<Document> documentMetadataSearch(@RequestParam String message, @RequestParam String question) {
//        return documentService.metadataSearch(message, question);
//    }
//
//    @GetMapping("/customerService")
//    public String customerService(@RequestParam String question) {
//
//        // 向量搜索
//        List<Document> documentList = documentService.search(question);
//
//        // 提示词模板
//        PromptTemplate promptTemplate = new PromptTemplate("{userMessage}\n\n 用以下信息回答问题:\n {contents}");
//
//        // 组装提示词
//        Prompt prompt = promptTemplate.create(Map.of("userMessage", question, "contents", documentList));
//
//        // 调用大模型
//        return chatClient.call(prompt).getResult().getOutput().getContent();
//    }
//}
